package org.scc.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.scc.model.Prayer;

/**
 * 代祷事项数据访问类
 * @author rzpeng
 *
 */
public class PrayerDao extends BaseDao{
	
	@Override
	protected String getMapper(String methodName) {
		return "org.scc.sqlmap.PrayerMapper." + methodName;
	}
	
	/**
	 * 添加代祷事项
	 * @param prayer
	 */
	public void add(Prayer prayer){
		insert( getMapper("add"), prayer, "add prayer error");
	}
	
	/**
	 * 更新代祷事项
	 * @param prayer
	 */
	public void update(Prayer prayer){
		update(getMapper("update"), prayer, "update prayer error");
	}
	
	/**
	 * 删除代祷事项
	 * @param ids
	 */
	public void delete(String ids){
		delete(getMapper("delete"), ids, "delete prayer error");
	}
	
	/**
	 * 查询用户创建的代祷事项
	 * @param userId
	 */
	public List<Prayer> findPageByUser(int userId, int rowBeginIndex, int rowCount){
		Map<String, Integer> param = new HashMap<String, Integer>();
		param.put("userId", userId);
		param.put("rowBeginIndex", rowBeginIndex);
		param.put("rowCount", rowCount);
		return selectList(getMapper("findPageByUser"), param, "find prayer page by user error");
	}
	
	public int getCountByUser(int userId){
		return selectOne(getMapper("selectCountByUser"), userId, "get count of user prayer error");
	}
	
	public Prayer load(int id){
		return selectOne(getMapper("load"), id, "load prayer error");
	}
	
}
